package ve.com.ucv.changedetection.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import ve.com.ucv.changedetection.io.ComparationIO;
import ve.com.ucv.changedetection.model.ConnectionManager;
import ve.com.ucv.changedetection.objects.Constants;
import ve.com.ucv.changedetection.objects.requests.ComparationRequest;
import ve.com.ucv.changedetection.objects.responses.ComparationResponse;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by josmaguirre on 1/13/15.
 */
@Controller
@RequestMapping("/comparaciones")
public class ComparationController extends ConnectionManager{
    ComparationIO comparationIO = null;
    ComparationResponse comparationResponse = null;

    @RequestMapping(value = "/obtenerComparaciones", method = RequestMethod.POST)
    @ResponseBody
    ComparationResponse getComparations(){
        comparationResponse = getComparationIO().getComparations();
        return comparationResponse;
    }

    @RequestMapping(value = "/guardarComparacion", method = RequestMethod.POST)
    @ResponseBody
    ComparationResponse saveComparations(@RequestBody ComparationRequest comparationRequest){
        comparationResponse = getComparationIO().saveComparation(comparationRequest);
        return comparationResponse;
    }

    @RequestMapping(value = "/modificarComparacion", method = RequestMethod.POST)
    @ResponseBody
    ComparationResponse modificarComparacion(@RequestBody ComparationRequest comparationRequest){
        comparationResponse = getComparationIO().modifyComparation(comparationRequest);
        return comparationResponse;
    }

    @RequestMapping(value = "/eliminarComparacion", method = RequestMethod.POST)
    @ResponseBody
    ComparationResponse eliminarComparacion(@RequestBody ComparationRequest comparationRequest){
        comparationResponse = getComparationIO().deleteComparation(comparationRequest);
        return comparationResponse;
    }

    public ComparationIO getComparationIO() {
        return comparationIO;
    }

    public void setComparationIO(ComparationIO comparationIO) {
        this.comparationIO = comparationIO;
    }

    public ComparationResponse getComparationResponse() {
        return comparationResponse;
    }

    public void setComparationResponse(ComparationResponse comparationResponse) {
        this.comparationResponse = comparationResponse;
    }
}
